<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			div {
				margin: 50px;
			}
			.div1 {
				width: 300px;
				background: gray;
			}
			.div2 {
				background: yellow;
			}
			.div3 {
				background: green;
				height: 100px;
				width: 100px;
			}
		</style>
	</head>

	<body>
		<div class="div1">
			div1
			<div class="div2">
				div2
				<div class="div3" id="first">
					first
				</div>
			</div>
		</div>

		<div class="div1">
			div1
			<div class="div2" style="position: relative;">
				div2 - position: relative
				<div class="div3" id="second">
					second
				</div>
			</div>
		</div>
	</body>

</html>

<script type="text/javascript">
	/* 标准浏览器下:
	 * offsetLeft  元素到它的offsetParent的距离
	 * 就近原则,定位到离元素最近的具有定位的父节点
	 */
	var first = document.querySelector('#first');
	console.log('#fist的offsetLeft:', first.offsetLeft); // 

	var second = document.getElementById('second');
	console.log('#second的offsetLeft:', second.offsetLeft); // 
</script>